package com.share.simple.rest;

import com.share.simple.model.ResultBean;
import com.share.simple.model.dto.LoginUserDto;
import com.share.simple.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @author:caifan
 * @since 2023/7/12
 */
@Tag(name = "登录")
@RestController
public class LoginRest {

    @Autowired
    private LoginService loginService;

    @Operation(summary = "登录")
    @PostMapping("/doLogin")
    public ResultBean<String> login(@RequestBody LoginUserDto loginUserDto) {
        return ResultBean.success(loginService.login(loginUserDto));
    }

    @Operation(summary = "登出")
    @PostMapping("/doLogout")
    public ResultBean<Boolean> logout(@RequestHeader("token")String token) throws ParseException {
        return ResultBean.success(loginService.logout(token));
    }
}
